require(['grid', 'layout'], function () {
    var $grid = $('#grid');
    var godrvAnaDriverInfo;
    function lineChange(event, treeId, treeNode) {
        if (treeNode.type === 'LINE') {
            searchRelatedDriver(treeNode.id);
            $("#lineName").html(treeNode.name);
        } else {
            $.messager.alert("提示", "请选择线路进行查看。");
        }
    }

    //左侧树
    commonFun.leftTreeNodeClickObj['lineAnaRelatedDriver'] = lineChange;

    //grid初始化
    function gridInit() {
        $grid.grid({
            url: "/lineAna/getRelatedDrvPage.htm",
            colModel: [
                {name: "drvId", label: 'drvId', key: true, hidden: true},
                {name: "drvName", label: '驾驶员名称', width: 80,formatter: 'customCurrency',formatoptions:{
	                redbtn:true,
	                css:'text-link c-blue',
	                clickFn:function(rowObject,cellvalue){
	                	godrvAnaDriverInfo(rowObject.drvId);
	                }
	            }
                },
                {name: "gender", label: '性别', width: 80, dict: "SEX00000"},
                {name: "ctcWay", label: '联系方式', width: 80},
                {name: "workEmpeEmpno", label: '员工工号', width: 80},
                {name: "timecardCardno", label: '考勤卡卡号', width: 80},
                {name: "", label: '', width: 800}
            ],
            multiselect: false,
            width:$(window).width() - 35,
            height: $(window).height() - 145
        });
    }
    
    godrvAnaDriverInfo = function(drvId){
    	var data = {};
    	data.drvId = drvId;
    	$.openTab('8252b8b5e5ff49c08b02f6865562b506','showDrvInfo',[data]);
    };

    function searchRelatedDriver(lineId) {
        $grid.grid('setGridParam', {
            datatype: "JSON",
            page: 1,
            postData: {'lineId': lineId}
        }).trigger("reloadGrid");
    }

    //layout 布局
    $('body').layout();

    gridInit();


    //如果左侧树有选择车辆则直接查询该车辆数据
    business.execFnByLeftTreeSelectNode('LINE', lineChange);
});